package com.ruoyi.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.supervise.domain.MainComplete;
import com.ruoyi.supervise.domain.MainLeft;
import com.ruoyi.supervise.domain.Mybigdata;
import com.ruoyi.supervise.domain.PieChart;
import com.ruoyi.supervise.domain.TbFocusProject;
import com.ruoyi.supervise.service.IIndexMainService;
import com.ruoyi.supervise.service.ITbFocusProjectService;
import com.ruoyi.system.domain.SysMenu;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysMenuService;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;

/**
 * 首页 业务处理
 * 
 * @author ruoyi
 */
@Controller
public class SysIndexController extends BaseController
{
    @Autowired
    private ISysMenuService menuService;
    
    @Autowired
    private ITbFocusProjectService tbFocusProjectService;
    
    @Autowired
    private IIndexMainService indexMainService;
    
    private String prefix = "smartsite";

    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        // 根据用户id取出菜单
        List<SysMenu> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("copyrightYear", Global.getCopyrightYear());
        mmap.put("demoEnabled", Global.isDemoEnabled());
		/* return "smartsite/index"; */
        return "indexnew";
    }
    
    @GetMapping("/smartsite")
    public String smartsite(ModelMap mmap)
    {
          return "smartsite/index";
    }
    
    @GetMapping("/decisionSupport")
    public String decisionSupport(ModelMap mmap)
    {
          return "decisionSupport/index";
    }
    
 // 系统首页
    @GetMapping("/indexnew")
    public String indexnew(ModelMap mmap)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        // 根据用户id取出菜单
        List<SysMenu> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("copyrightYear", Global.getCopyrightYear());
        mmap.put("demoEnabled", Global.isDemoEnabled());
        return "indexnew";
    }
    
    @GetMapping("/mapproject")
    public String mapproject(ModelMap mmap,HttpSession session)
    {
    	session.setAttribute("projectName", "海南陵水香水湾B区C-01-1地块项目");
        return "supervise/project/allproject";
    }

    // 系统介绍
    @GetMapping("/system/main")
    public String main(ModelMap mmap) throws Exception
    {
//        mmap.put("version", Global.getVersion());
//        Server server = new Server();
//        server.copyTo();
//        mmap.put("server", server);
    	List<TbFocusProject> tfpList = tbFocusProjectService.selectMainFocusProject();
    	mmap.put("tfpList", tfpList);
    	List<MainLeft> mlList = indexMainService.mainLeft();
    	mmap.put("mlList", mlList);
    	//年度施工许可数据统计开始
    	Mybigdata ct = new Mybigdata();
    	ct.setBeginIssueDate(DateUtil.format(DateUtil.beginOfYear(DateUtil.date()),DatePattern.NORM_DATE_PATTERN));
    	ct.setEndIssueDate(DateUtil.format(DateUtil.endOfYear(DateUtil.date()),DatePattern.NORM_DATE_PATTERN));
    	//ct.setBeginIssueDate("2019-01-01");
    	//ct.setEndIssueDate("2019-12-31");
    	//年度施工许可数据统计中的本年度施工许可项目总数
    	String consturctionTotal = indexMainService.countConsturctionTotal(ct);
    	mmap.put("consturctionTotal", consturctionTotal);
    	//年度施工许可数据统计中的本年度施工许可工程项目类型分布图
    	List<PieChart> pcList = indexMainService.selectNumGroupByProjectType(ct);
    	mmap.put("pcList", pcList);
    	//年度施工许可数据统计中的本年度施工许可工程项目数量对比图
    	List<PieChart> columnarList = indexMainService.selectConsturctionNumGroupByMonth(ct);
    	mmap.put("columnarList", columnarList);
    	//年度施工许可数据统计中的本年房建工程施工许可数中的数量
    	ct.setEngineeringType("房屋建筑工程");
    	String countConsturctionTotalFJ = indexMainService.countConsturctionTotal(ct);
    	mmap.put("countConsturctionTotalFJ", countConsturctionTotalFJ);
    	//年度施工许可数据统计中的本年房建工程施工许可数中的规模
    	String consturctionDevelopmentScopeFJ = indexMainService.sumConsturctionDevelopmentScope(ct);
    	mmap.put("consturctionDevelopmentScopeFJ", consturctionDevelopmentScopeFJ);
    	//年度施工许可数据统计中的本年房建工程施工许可数中的总金额
    	String consturctionCompactPriceFJ = indexMainService.sumConsturctionCompactPrice(ct);
    	mmap.put("consturctionCompactPriceFJ", consturctionCompactPriceFJ);
    	//年度施工许可数据统计中的本年市政工程施工许可数中的数量
    	ct.setEngineeringType("市政");
    	String countConsturctionTotalSZ = indexMainService.countConsturctionTotal(ct);
    	mmap.put("countConsturctionTotalSZ", countConsturctionTotalSZ);
    	//年度施工许可数据统计中的本年市政工程施工许可数中的总金额
    	String consturctionCompactPriceSZ = indexMainService.sumConsturctionCompactPrice(ct);
    	mmap.put("consturctionCompactPriceSZ", consturctionCompactPriceSZ);
    	
    	//年度竣工备案数据统计开始
    	MainComplete mc=new MainComplete();
    	mc.setBeginAuthorizedDate(DateUtil.format(DateUtil.beginOfYear(DateUtil.date()),DatePattern.NORM_DATE_PATTERN));
    	mc.setEndAuthorizedDate(DateUtil.format(DateUtil.endOfYear(DateUtil.date()),DatePattern.NORM_DATE_PATTERN));
    	//mc.setBeginAuthorizedDate("2019-01-01");
    	//mc.setEndAuthorizedDate("2019-12-31");
    	//年度竣工备案数据统计中的本年度竣工备案项目总数
    	String completeTotal = indexMainService.countCompleteTotal(mc);
    	mmap.put("completeTotal", completeTotal);
    	//年度竣工备案数据统计中的本年度竣工备案工程项目类型分布图
    	List<PieChart> completePC=indexMainService.selectCompleteNumGroupByEngineeringCategory(mc);
    	mmap.put("completePC", completePC);
    	//年度竣工备案数据统计中的本年度竣工备案工程项目数量对比图
    	List<PieChart> completeColumnar = indexMainService.selectCompleteNumGroupByMonth(mc);
    	mmap.put("completeColumnar", completeColumnar);
    	//年度竣工备案数据统计中的本年房建工程竣工备案数的数量
    	mc.setEngineeringType("房屋建筑工程");
    	String completeTotalFJ = indexMainService.countCompleteTotal(mc);
    	mmap.put("completeTotalFJ", completeTotalFJ);
    	//年度竣工备案数据统计中的本年房建工程竣工备案数的规模
    	String completeDevelopmentScopeFJ = indexMainService.sumCompleteDevelopmentScope(mc);
    	mmap.put("completeDevelopmentScopeFJ", completeDevelopmentScopeFJ);
    	//年度竣工备案数据统计中的本年房建工程竣工备案数的总金额
    	String completeCompactPriceFJ = indexMainService.sumCompleteCompactPrice(mc);
    	mmap.put("completeCompactPriceFJ", completeCompactPriceFJ);
    	//年度竣工备案数据统计中的本年市政工程竣工备案数的数量
    	mc.setEngineeringType("市政");
    	String completeTotalSZ = indexMainService.countCompleteTotal(mc);
    	mmap.put("completeTotalSZ", completeTotalSZ);
    	//年度竣工备案数据统计中的本年市政工程竣工备案数的总金额
    	String completeCompactPriceSZ = indexMainService.sumCompleteCompactPrice(mc);
    	mmap.put("completeCompactPriceSZ", completeCompactPriceSZ);
        return "main";
    }
    
    @GetMapping("/indexmain")
    public String indexmain()
    {
        return prefix+"/main";
    }
    
    @GetMapping("/indextajijianche")
    public String indextajijianche()
    {
        return prefix+"/tajijianche";
    }
    
    @GetMapping("/indexshengjiangji")
    public String indexshengjiangji()
    {
        return prefix+"/shengjiangji";
    }
    
    @GetMapping("/indexenvironment")
    public String indexenvironment()
    {
        return prefix+"/environment";
    }
    
    @GetMapping("/indexvideo")
    public String indexvideo()
    {
        return prefix+"/video";
    }
    
    @GetMapping("/indexlaborName")
    public String indexlaborName()
    {
        return prefix+"/laborName";
    }
    
    @GetMapping("/tjDetail")
    public String tjDetail(ModelMap mmap,HttpSession session)
    {
        return "supervise/project/tjdetail";
    }
    
    @GetMapping("/sjjDetail")
    public String sjjDetail(ModelMap mmap,HttpSession session)
    {
        return "supervise/project/sjjdetail";
    }
}
